<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .layui-input-block {
            width: 300px;
            display: inline-block;
        }
        .layui-form-label {
            width: 120px;
        }
        .gongneng{
            width: 100%;
            margin-left:180px;
        }
    </style>
</head>
<link rel="stylesheet" href="../../css/layui.css">
<script src="/js/layui/layui.all.js"></script>
<script src="/admin/js/token.js"></script>
<body>
<div style="margin: 5% 5%">
    <div class="controller">
        <form class="layui-form" action="" lay-filter="example">

            <div class="layui-form-item" style="display: none;">
                <div class="layui-input-block">
                    <input type="text" name="terminalId" lay-verify="title" autocomplete="off"  class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属分组:</label>
                <div class="layui-input-block" style="margin-left: 0px">
                    <select name="terminalGroup">
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">型号:</label>
                <div class="layui-input-block" style="margin-left: 0px">
                    <input type="text" name="terminalSystemModel" lay-verify="title" autocomplete="off" placeholder="请输入型号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">房间号:</label>
                <div class="layui-input-block" style="margin-left: 0px">
                    <input type="text" name="terminalRoom" lay-verify="title" autocomplete="off" placeholder="请输入房间号:" class="layui-input">
                </div>
            </div>






            <div class="layui-form-item">
                <div class="layui-input-block" style="margin-left: 0px">
                    <div class="gongneng">

                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="update">修改</button>
                        <a><button type="button" class="layui-btn layui-btn-normal" id="quxiao" onclick="formClose()">取消</button></a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>



   var stationid=localStorage.getItem('groupStationId');

    /**
     *获取当前的站点所有分组列表
     *
     */
    $.ajax({
        type: 'GET',
        url: '/admin/group/stationGroup?stationId='+stationid,
        success: function (data) {
            $.each(data.data, function (key, val) {
                var option1 = $("<option>").val(val.groupId).text(val.groupName);
                $("select[name='terminalGroup']").append(option1);
            });
            layui.form.render('select');
        }
    });


    /*
    * 查询获取的终端Id
    * */


        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            ,table = layui.table
            , $ = layui.jquery
            , laydate = layui.laydate;
        // form.render()

        var s=layui.data("s");
        var tid=s.terminal.terminal_id;
        $("input[name='terminalId']").val(tid);
        console.log(tid);
        $.ajax({
            type: "get",
            url: "/admin/terminal/byIdTerminal" ,
            data: {
                "terminalId": $("input[name='terminalId']").val()
            },
            success: function (res) {
                console.log(res)
                form.val('example', {
                    "terminalSystemModel": res.data.terminalSystemModel,
                    "terminalRoom": res.data.terminalRoom,
                    "terminalGroup": res.data.terminalGroup
                })
            }
        });


        form.on('submit(update)',function (data) {
            $.ajax({
                url:"/admin/terminal/modifyByIdIpMacFj",
                type:"put",
                dataType:"JSON",
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(data.field),
                // beforeSend: function () {
                //     this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
                // },
                success:function (res) {
                    console.log(res)
                    if (res.code==200){
                        layer.msg("修改成功",{icom:5,time: 1000}
                            ,function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                //layer.msg(index);
                                parent.layer.close(index); //再执行关闭

                            }

                            ) ; //失败的表情


                        return ;
                    } else if(res.code==500){
                        layer.msg("修改失败",{
                            icon:6,  //失败的表情
                            time:1000 //2秒关闭

                        });
                    }
                },
                error:function () {
                    layer.msg("网络原因修改失败",{
                        icon:2,time: 1000
                    })
                },
                complete:function () {
                    layer.close(this.layerIndex);
                }
            })
            return false;
        })

        //关闭自身
        window.formClose = function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //layer.msg(index);
            parent.layer.close(index); //再执行关闭
        }





</script>
</html>